package sugarbind_input

class StructureController {

    def scaffold = true
	
	def displayCfg = {
		def structure = Structure.get(params.id)
		response.contentType = "image/png"
		response.contentLength = structure?.cfg.length
		response.outputStream.write(structure?.cfg)
	}
	
	def displayUoxfcol = {
		def structure = Structure.get(params.id)
		response.contentType = "image/png"
		response.contentLength = structure?.uoxfcol.length
		response.outputStream.write(structure?.uoxfcol)
	}
	
	def displayText = {
		def structure = Structure.get(params.id)
		response.contentType = "image/png"
		response.contentLength = structure?.text.length
		response.outputStream.write(structure?.text)
	}
	
	def findLigands = {
//		println("params structure : " +params.structure.id + " " + Structure.get(params.structure.id))
//		
//		def structure = Structure.get(params.structure.id)
//		
//		render(template: 'ddlLigands', model:  [ligands : structure.ligands])
		
		println("params : " +params)
		
		def structure
		def ligands
		
		try
		{
			structure = Structure.get(params.structure.id)
		}
		catch(Exception ex)
		{
			println(ex.getMessage())
		}
	
		if(structure != null)
		{
			ligands = structure.ligands
		}
		else
		{
			ligands = Structure.listStructures()
		}
		render(template: 'ddlLigands', model:  [ligands : ligands])		
	  }
	
	def findStructures = {
		println("findStructures params : " +params)
			
		def structures = Structure.listStructures()
		def selected


		try
		{
			selected = Structure.get(params.structure.id)
		}
		catch(Exception ex)
		{
			println(ex.getMessage())
		}
		println(structures)
		println(selected)
		
		render(template: 'ddlStructures', model:  [structures : structures, selected:selected])
	  }
}
